
include ../Makefile.common

OBJDIR       = .obj/
DEPDIR       = .dep/
SOURCEFILES  = $(wildcard *.cc)
TARGETS      = $(patsubst %.cc,%,$(SOURCEFILES))
DEPS         = $(addprefix $(DEPDIR),$(SOURCEFILES:.cc=.d))
BINFILES     = $(patsubst %.cc,%.x,$(SOURCEFILES))
INTEL_COMPILER_TYPE = `mpicc --version | grep icc`


LINK         += -L$(DYLIB_PATH) -lfemlib $(LDFLAGS) $(EX_LDFLAGS)

all: $(OBJDIR) $(DEPDIR) $(TARGETS)

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif

$(OBJDIR):
	$(MKDIR) $(OBJDIR)

$(DEPDIR):
	$(MKDIR) $(DEPDIR)

$(OBJDIR)%.o: %.cc
	$(CXX) $(INCDIRS) $(CXXFLAGS) -o $@ -c $< 

$(DEPDIR)%.d: %.cc $(DEPDIR)
	@$(CXX) -MM $(INCDIRS) $(CXXFLAGS) $< \
		| sed 's/$*.o/$(OBJDIR:/=\/)$*.o/g' \
	| sed 's/$*.o/& $(subst /,\/,$@)/g' > $@

clean:
	$(RM) $(BINFILES)
	$(RMDIR) $(OBJDIR) $(DEPDIR)

$(TARGETS): % : $(OBJDIR)%.o
	$(CXX) -o $@.x $< $(LINK)
